const swaggerJsdoc = require('swagger-jsdoc');

const swaggerOptions = {
  definition: {
    openapi: '3.0.0',
    info: {
      title: 'Personal Film Review API',
      version: '1.0.0',
      description: 'API 文档',
    },
    components: {
      schemas: {
        // 在这里定义通用的 schemas
        NewUser: {
          type: 'object',
          properties: {
            username: { type: 'string' },
            email: { type: 'string', format: 'email' },
            password: { type: 'string' },
          },
          required: ['username', 'email', 'password'],
        },
        LoginRequest: {
          type: 'object',
          properties: {
            email: { type: 'string', format: 'email' },
            password: { type: 'string' },
          },
          required: ['email', 'password'],
        },
        Movie: {
          type: 'object',
          properties: {
            id: { type: 'integer' },
            title: { type: 'string' },
            description: { type: 'string' },
            rating: { type: 'number' },
            poster_url: { type: 'string' },
            release_year: { type: 'integer' },
            tags: { type: 'array', items: { type: 'integer' } },
            count_reviews: { type: 'integer' },
          },
          required: ['id', 'title'],
        },
        Review: {
          type: 'object',
          properties: {
            id: { type: 'integer' },
            movie_id: { type: 'integer' },
            user_id: { type: 'integer' },
            user_rating: { type: 'integer' },
            content: { type: 'string' },
            likes: { type: 'integer' },
            created_at: { type: 'string', format: 'date-time' },
            update_time: { type: 'string', format: 'date-time' },
            username: { type: 'string' },
            poster_url: { type: 'string' },
          },
          required: ['id', 'movie_id', 'user_id', 'user_rating', 'content', 'created_at'],
        },
      },
      securitySchemes: {
        JWT: {
          type: 'apiKey',
          name: 'Authorization',
          in: 'header',
        },
      },
    },
    security: [{ JWT: [] }],
  },
  apis: ['./routes/*.js'],
};

module.exports = swaggerOptions;